<template>
  <div>
      <el-dialog
        title="选择公式"
        :visible.sync="dialogVisible"
        append-to-body
        width="30%">
        <el-row>
          <el-col :span="24">
              <el-form :model="form" :inline='true' class="demo-form-inline"> 
                <el-col :span="12">
                  <el-form-item label="公式">
                    <el-select v-model="form.gsId" placeholder="请选择" clearable
                                 @change="elGsChange()" class="xiaLa" style="width:160px;">
                        <el-option :label="'平均分配'" :value="-1">
                        </el-option>
                        <el-option v-for="(item1,index) in gsData " :key="index" :label="item1.gsMc" :value="item1.id">
                        </el-option>
                      </el-select>
                </el-form-item>
                </el-col>
                <el-col :span="12" v-if="text=='geren'">
                    <el-form-item>
                      <el-checkbox v-model="form.jkjbj">含加扣奖</el-checkbox>
                    </el-form-item>
                </el-col>
              </el-form> 
          </el-col>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submint()">确 定</el-button>
            <el-button @click="close()">取 消</el-button>
        </span>
     </el-dialog>
  </div>
</template>

<script>
import {getJjDeptJjgtoPrant} from '@/api/admin/sysformula'
import { getFzList,saveGsAll} from '@/api/jiangjin/jiangjinryfzmxb'
export default {
    data(){
        return{
            dialogVisible:false,
            form:{},
            gsData:[],
            deptId:'',
            jiList:[],
            row:{},
            getSpanArr:[],
            text:''
        }
    },
    methods:{
        init(rows,text){
            this.dialogVisible=true;
            this.rows=rows;
            this.text=text
            if(this.text=='geren'){
            // if(this.row.jkjbj==1){
            //   this.$set(this.form,'jkjbj',true)
            // }else{
            //   this.$set(this.form,'jkjbj',false)
            // }
          }
            this.$set(this.form,'gsId',-1)
            this.getGsListOption(text)
            //this.getRenJi(row.id)
        },
        close(){
          this.dialogVisible=false
          this.form.gsId=''
        },
        //提交
        submint(){
          if(!this.form.gsId){
            this.$message.closeAll()
            this.$message.warning('请选择公式!')
            return false;
          }
          let names;
          //gsMc
          if(this.form.gsId!=-1){
           names= this.gsData.filter(item=>{
              return item.id==this.form.gsId
            })
            
            this.$set(this.row,'gsName',names[0].gsMc)
          }else{
            this.$set(this.row,'gsName','平均分配')
          }
           var params;
          if(this.text=='geren'){
            if(this.form.jkjbj){
              this.form.jkjbj=1
            }else{
              this.form.jkjbj=0
            }
          }else{
              this.form.jkjbj=0
          }
        params={
             rows:this.rows,
             id:this.form.gsId, 
             name:names[0].gsMc,
             jkjbj:this.form.jkjbj
         }
         
          saveGsAll(params).then(res=>{
            if(res.data.code==0){
              this.$message.closeAll()
              this.$message.success('选择成功!')
              this.close()
              this.$emit('chaifenChild')
            }
          })
        },
        elGsChange(){

        },
        getRenJi(fzid){
          getFzList(fzid).then(res=>{
            this.renList=res.data.data;
            this.renList=this.renList.map(item=>{
                item.jjJe=0;
                return item
            })
           // this.pingJun()
          })
          jiGougetFzList(fzid).then(res=>{
            this.jiList=res.data.data.map(item=>{
                item.jjJe=0;
                item.deptName=item.jgDeptName
                item.deptCode=item.jgDeptCode
                return item
            })
            this.pingJun()
          })
      },
         //取得基本数据
      getGsListOption(text) {
        if(text=='geren'){
          var params={
              id: this.deptId, 
              gsType: '奖金算法', 
              gsFl: '个人'
          }
        }
        if(text=='jigou'){
          var params={
              id: this.deptId, 
              getJJxNamesType: '奖金算法', 
              gsFl: '部门'
          }
        }
        //取得公式数组
        getJjDeptJjgtoPrant(params).then(res => {
          this.gsData = res.data.data;
        })
      },
    }
}
</script>

<style>

</style>